<template>
    <base-breadcrumb>
        <searchData :search-data="searchArr" @search="search" />
        <a-card>
            <div class="table-operator">
                <a-button v-btnPermission="'bm_011_add_01'" type="primary" icon="plus" @click="handleUpdate('add', {})">
                    新增
                </a-button>
            </div>
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                        工程计量确权(不含税)( 万元)：
                        <a>{{ from.confirmationRights }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        截止目前项目实际产值(不含税)(万元)：
                        <a>{{ from.projectActOutPutValueSoFars }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        截止目前项目实际成本(不含税)(万元)：
                        <a>{{ from.projectActCostSoFars }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        工程计量确认率%：
                        <a>{{ from.confirmationRate }}</a>
                    </span>
                    <br />

                    <span>
                        钢筋业主确认量(t)：
                        <a>{{ from.totalSteelOwnerConfirm }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        钢筋实际消耗量(t)：
                        <a>{{ from.totalSteelUsed }}</a>
                    </span>

                    <a-divider type="vertical" />
                    <span>
                        钢筋优化率(%)：
                        <a>{{ from.steelOptimizeRate }}</a>
                    </span>
                </template>
            </a-alert>
            <!-- <div class="table-operateors mb20">
                <div class="pub-table-select-count" style="margin: 10px 0">
                    <a-icon type="info-circle" theme="twoTone" />
                </div>
            </div> -->
            <list-table
                ref="table"
                size="default"
                row-key="key"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                show-pagination="auto"
            >
                <span slot="description" slot-scope="text">
                    <ellipsis :length="8" tooltip>{{ text }}</ellipsis>
                </span>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a v-btnPermission="'bm_011_loo_04'" @click="handleUpdate('look', record)">查看</a>
                    <template
                        v-if="
                            record.auditStatus != 'SUBMITTED' &&
                            record.auditStatus != 'PAST' &&
                            record.auditStatus != 'ABOLISH'
                        "
                    >
                        <a @click="handleUpdate('edit', record)"  v-btnPermission="'bm_011_edi_02'">编辑</a>
                    </template>
                    <span v-if="record.auditStatus == 'SUBMITTED' && userId === record.creatorId&&hideBuquBtn()">
                        <a @click="handleUpdate('undo', record, '撤销')">撤销</a>
                    </span>
                    <span v-if="record.auditStatus == 'PAST'" v-btnPermission="'bm_011_tov_05'">
                        <a @click="handleUpdate('invalid', record, '作废')" >作废</a>
                    </span>
                    <span v-if="record.auditStatus == 'DRAFT'" v-btnPermission="'bm_011_del_03'">
                        <a @click="handleUpdate('del', record, '删除')">删除</a>
                    </span>
                    <span
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED'||
                            record.auditStatus === 'ABOLISH'
                        "
                        v-btnPermission="'bm_011_moi_05'"
                    >
                        <approval-button :id="record.id" :status="record.auditStatus" />
                    </span>
                        </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status :status="record.auditStatus" :is-approval="true" conversion="en" :text="text" />
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import {
    getCostAnalysisAudit,
    delCostAnalysisAudit,
    getCostAnalysisAuditCount,
    cancelCostAnalysisAudit
} from '@/api/businessAffairs/revenueAndCost'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
const columns = [
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '月份',
        dataIndex: 'monthDate',
        width:100
    },
    {
        title: '工程计量确权(不含税)(万元)',
        dataIndex: 'confirmationRight'
    },

    {
        title: '截止目前项目实际产值(不含税)(万元)',
        dataIndex: 'projectActOutPutValueSoFar',
         width:150
    },
    {
        title: '截止目前项目实际成本(不含税)(万元)',
        dataIndex: 'projectActCostSoFar',
         width:150
    },
    {
        title: '工程计量确认率(%)',
        dataIndex: 'confirmationRate'
    },
    {
        title: '累计钢筋确认量(t)',
        dataIndex: 'totalSteelOwnerConfirm'
    },
    {
        title: '累计钢筋实际消耗量(t)',
        dataIndex: 'totalSteelUsed'
    },
    {
        title: '钢筋优化率(%)',
        dataIndex: 'steelOptimizeRate'
    },
    {
        title: '填报人',
        dataIndex: 'informant'
    },
    {
        title: '填报时间',
        dataIndex: 'informantTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '230px',
        fixed: 'right',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '月份',
        value: 'monthDate',
        type: 'month'
    },
    {
        name: '填报人',
        value: 'informant',
        type: 'input'
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange'
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: typeListApproval
    },
    {
        name: '钢筋优化率',
        value: 'steelOptimizeRateType',
        type: 'select',
        data: [
            {
                value: '1',
                label: '>=10%'
            },
            {
                value: '2',
                label: '<10%'
            }
        ]
    }
]
import { typeListApproval } from '@/utils/util'
import { STable } from '@/components'
export default {
    name: 'a' + Date.now(),
    components: {
        STable
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            from: {},
            queryParam: {},
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                console.log(requestParameters)
                this.getCostAnalysisAuditCount(requestParameters)
                const [err, res] = await getCostAnalysisAudit(requestParameters)

                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            }
        }
    },
    methods: {
        async getCostAnalysisAuditCount(requestParameters) {
            const [err, res] = await getCostAnalysisAuditCount(requestParameters)
            if (!err) {
                this.from = res.data
                console.log(this.from)
            }
        },
        //搜索
        search(val) {
            console.log(val)
            this.queryParam = {
                ...val,
                informantTimeBegin:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[0].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0,
                informantTimeEnd:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[1].format('YYYY-MM-DD HH:mm:ss')) ||
                    void 0
            }
            delete this.queryParam.startEndDate
            console.log(this.queryParam)
            this.$refs.table.refresh(true)
        },
        async delCostAnalysisAudit(data, type, text) {
            const [err, res] =
                type == 'del'
                    ? await delCostAnalysisAudit({ id: data.id })
                    : await cancelCostAnalysisAudit({ id: data.id, type: type == 'undo' ? 1 : 2 })

            if (!err) {
                this.$message.success(text + '成功')
                this.$refs.table.refresh(true)
            }
        },
        //新增text
        async handleUpdate(type, data = {}, text = '') {
            if (type == 'del' || type == 'undo' || type == 'invalid') {
                let that = this
                this.$confirm({
                    title: '温馨提示',
                    content: '确定是否' + text + '数据？',
                    okText: '确认',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: () => {
                        return that.delCostAnalysisAudit(data, type, text)
                    }
                })
            } else {
                this.$router.push({
                    name: 'updateCostAnalysisAudit',
                    query: {
                        id: data.id || '',
                        pageType: type
                    }
                })
            }
        }
    }
}
</script>


